<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/


empty($do) && $do = 'list';
if ($do == 'list') {
    //上班时间不能超过12点
    if (get_date('H',PHP_TIME)<12)
	{
	//防止重复打卡
	$registration = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."registration where uid='".$_USER->id."' and date='".get_date('Y-m-d',PHP_TIME)."' ORDER BY id desc limit 0,1");
	if($registration[date]==get_date('Y-m-d',PHP_TIME)){
		$webstartdate=$registration[startdate];
		$datetype=1;
	}
	else{
		$webstartdate=get_date('Y-m-d H:i:s',PHP_TIME);
		$datetype=0;
	}
		include_once('template/add.php');
	}else
	{
		goto_page('admin.php?ac=edit&fileurl=registration&do=edit');
	}
	
} elseif ($do == 'save') {
	
	$savetype = getGP('savetype','P');
	$startdate = getGP('startdate','P');
	$startnote = getGP('startnote','P');
	if ((getGP('starthour','P')-GET_INC_CONFIG_INFO("swork"))>=0){
		$getstarthour = (getGP('starthour','P')-GET_INC_CONFIG_INFO("swork")).".".getGP('starthour1','P');
		$startyype="迟到";
	}else{
		$getstarthour =0;
		$startyype="正常";
	}
	
	
	//主表信息
	$registration = array(
		'name' => $_USER->name,
		'startip' => get_onlineip(),
		'startdate' => $startdate,
		'startnote' => $startnote,
		'uid' => $_USER->id,
		'startyype' => $startyype,
		'date' => get_date('Y-m-d',PHP_TIME),
		'starthour' => $getstarthour
	);
	//写入主表信息
	insert_db('registration',$registration);
	$id=$db->insert_id();
	$content=$_USER->name.get_inc_log(1).get_onlineip().get_inc_log(1).$startdate.get_inc_log(1).$startnote.get_inc_log(1).$startyype.get_inc_log(1).$getstarthour;
	$title='上班考勤登记';
	get_oa_log_dbadd($id,$content,$title,7,$_USER->id);
    goto_page('admin.php?ac=index&fileurl=registration');

}
?>